<template>
  <div>
    <common-head title="编辑地址" bg="#634"></common-head>
    <div class="main">
      <van-address-edit
        :area-list="areaInfo"
        show-postal
        show-set-default
        :address-info = "addressInfo"
        :area-columns-placeholder="['省', '市', '区']"
        @save="onSave"
      />
    </div>
  </div>
</template>

<script>
import CommonHead from '@/components/CommonHead'
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
      addressInfo: {}
    }
  },
  created () {
    this.initAddressInfo()
  },
  methods: {
    // 初始化默认数据
    initAddressInfo () {
      this.addressInfo = this.contacts[parseInt(this.$route.params.index)]
    },
    onSave (contact) {
      this.editContact({ contact, index: parseInt(this.$route.params.index) })
      this.$toast('修改成功')
      this.$router.go(-1)
    },
    ...mapMutations(['editContact'])
  },
  computed: {
    ...mapState(['areaInfo', 'contacts'])
  },
  components: {
    CommonHead
  }
}
</script>

<style lang="scss" scoped>
</style>
